package manageHandler

import (
	"gitee.com/fierce_wolf/go-fox-edge-channel-common/channelRestfulNotify"
	"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Method"
)

type ManageHandler struct {
	ChannelName  string
	Manufacturer string
	DeviceType   string
	DeviceName   string
}

func (e *ManageHandler) CreateChannel(serviceKey string) {
	// 检测：是否输入了通道名称前缀
	if e.ChannelName == "" {
		return
	}

	// 格式化名称
	chnName := e.ChannelName + "-" + serviceKey

	// 填写通道参数
	channelParam := make(map[string]interface{})
	channelParam["serviceKey"] = serviceKey

	// 发出消息
	channelRestfulNotify.CreateChannel(chnName, channelParam)
}

func (e *ManageHandler) CreateDevice(serviceKey string) {
	// 检测：是否输入了厂商、设备类型、设备名称
	if Method.HasEmpty(e.Manufacturer, e.DeviceType, e.DeviceName) {
		return
	}

	// 格式化名称
	devName := e.DeviceName + "-" + serviceKey
	// 格式化名称
	chnName := e.ChannelName + "-" + serviceKey

	// 填写通道参数
	channelParam := make(map[string]interface{})
	channelParam["serviceKey"] = serviceKey

	// 发出消息
	channelRestfulNotify.CreateDevice(e.Manufacturer, e.DeviceType, devName, chnName, channelParam)
}
